package Communication;

import java.io.Serializable;
import java.util.HashMap;
import Gauges.GaugeName;

/**
 * Wrapper to save boat data. Data will be overwritten instead of creating multiple instances.
 * @author Rick & Sietse
 *
 */
public class BoatDataWrapper implements Serializable 
{
	private static final long serialVersionUID = 1L;

	private int angle, 
				sailPosition, 
				rudderPosition, 
				windDirection, 
				motor,
				keel, 
				controlMethod, 
				RFID, 
				emergencySituation,
				emergencyStop,
				speed,
				bluetooth;
	
	private long timeStamp;
	
	private HashMap<GaugeName, Integer> allData;
	
	public BoatDataWrapper()
	{
		allData = new HashMap<GaugeName, Integer>();
		
		this.setAngle(128);
		this.setSailPosition(128);
		this.setRudderPosition(128);
		this.setWindDirection(128);
		this.setMotor(1);
		this.setKeel(1);
		this.setControlMethod(0);
		this.setEmergencySituation(0);
		this.setEmergencyStop(0);
		this.setBluetoothConnection(0);
	}
	
	public HashMap<GaugeName, Integer> getAllData()
	{
		return allData;
	}
	/**
	 * Function to set all parameters at the same time.
	 * @param angle
	 * @param sailPosition
	 * @param rudderPosition
	 * @param windDirection
	 * @param motor
	 * @param keel
	 * @param controlMethod
	 * @param RFID
	 * @param speed
	 * @param timeStamp
	 */
	public void setAllData(int angle, int sailPosition, int rudderPosition, int windDirection, int motor, int keel, int controlMethod, int RFID, int speed, long timeStamp)
	{
		allData.put(GaugeName.ANGLE, angle);		
		this.angle = angle;
		allData.put(GaugeName.SAIL, sailPosition);
		this.sailPosition = sailPosition;
		allData.put(GaugeName.HELM, rudderPosition);
		this.rudderPosition = rudderPosition;
		allData.put(GaugeName.WIND, windDirection);
		this.windDirection = windDirection;
		allData.put(GaugeName.MOTOR, motor);
		this.motor = motor;
		allData.put(GaugeName.KEEL, keel);
		this.keel = keel;
		allData.put(GaugeName.CONTROL, controlMethod);
		this.controlMethod = controlMethod;
		allData.put(GaugeName.RFID, RFID);
		this.RFID = RFID;
		allData.put(GaugeName.SPEED, speed);
		this.speed = speed;

		this.timeStamp = timeStamp;
	}
	public void clearHashMap()
	{
		allData.clear();
	}
	
	
	public int getSpeed()
	{
		return speed;
	}
	public void setSpeed(int value)
	{
		speed = value;
		allData.put(GaugeName.SPEED, value);
	}
	
	public int getAngle() 
	{
		return angle;
	}
	public void setAngle(int angle) 
	{
		if (angle > 255)
			angle -= 255;
		if (angle < 0)
			angle += 255;
		this.angle = angle;
		allData.put(GaugeName.ANGLE, angle);
	}
	
	public int getSailPosition() 
	{
		return sailPosition;
	}
	public void setSailPosition(int sailPosition) 
	{
		if (sailPosition >= 255)
			sailPosition = 255;
		if (sailPosition <= 0)
			sailPosition = 0;
		this.sailPosition = sailPosition;
		allData.put(GaugeName.SAIL, sailPosition);
	}
	
	public int getRudderPosition() 
	{
		return rudderPosition;
	}
	public void setRudderPosition(int rudderPosition) 
	{
		if (rudderPosition >= 255)
		{
			rudderPosition = 255;
		}
		if (rudderPosition <= 0)
			rudderPosition = 0;
		this.rudderPosition = rudderPosition;
		allData.put(GaugeName.HELM, rudderPosition);
	}
	
	public int getWindDirection() 
	{
		return windDirection;
	}
	public void setWindDirection(int windDirection) 
	{
		if (windDirection >= 255)
		{
			windDirection = 255;
		}
		if (windDirection <= 0)
			windDirection = 0;
		this.windDirection = windDirection;
		allData.put(GaugeName.WIND, windDirection);

	}
	
	public int getMotor() 
	{
		return motor;
	}
	public void setMotor(int motor) 
	{
		this.motor = motor;
		allData.put(GaugeName.MOTOR, motor);
	}
	
	public int getKeel() 
	{
		return keel;
	}
	public void setKeel(int keel) 
	{
		this.keel = keel;
		allData.put(GaugeName.KEEL, keel);
	}
	public int getControlMethod() 
	{
		return controlMethod;
	}
	public void setControlMethod(int controlMethod) 
	{
		this.controlMethod = controlMethod;
		allData.put(GaugeName.CONTROL, controlMethod);
	}
	public int getRFID() 
	{
		return RFID;
	}
	public void setRFID(int RFID) 
	{
		this.RFID = RFID;
		allData.put(GaugeName.RFID, RFID);
	}
	public long getTimeStamp() 
	{
		return timeStamp;
	}
	public void setTimeStamp(long timeStamp) 
	{
		this.timeStamp = timeStamp;
	}
	
	public void setEmergencySituation(int value)
	{
		this.emergencySituation = value;
		allData.put(GaugeName.EMERGENCYSITUATION, value);
	}
	
	public int getEmergecySituation()
	{
		return this.emergencySituation;
	}
	
	public void setEmergencyStop(int value)
	{
		this.emergencyStop = value;
		allData.put(GaugeName.EMERGENCYSTOP, value);
	}
	
	public int getEmergecyStop()
	{
		return this.emergencyStop;
	}
	public void setBluetoothConnection(int value)
	{
		this.bluetooth = value;
		allData.put(GaugeName.BLUETOOTH, value);
	}
	public int getBluetoothConnection()
	{
		return this.bluetooth;
	}

}
